package com.credit.jumu.playcard.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 2017/10/23/023.
 */

public class DataSharedPreference {
	/**
	 * The file name.
	 */
	private String fileName = "preference_data";
	static SharedPreferences mSharedPreferences = null;
	private static DataSharedPreference data;

	public DataSharedPreference(Context context) {
		if (mSharedPreferences == null) {
			mSharedPreferences = context.getSharedPreferences(fileName,
					Context.MODE_PRIVATE);
		}
	}

	public SharedPreferences getSharedPreferences() {
		return mSharedPreferences;
	}

	public static DataSharedPreference getIntance(Context context) {
		if (data == null) {
			data = new DataSharedPreference(context);
		}
		return data;
	}

	//手机唯一标识UUID
	public void setUUID(String uuid) {
		if (mSharedPreferences != null) {
			SharedPreferences.Editor editor = mSharedPreferences.edit();
			editor.putString("uuid", uuid);
			editor.commit();
		}
	}

	public String getUUID() {
		if (mSharedPreferences != null) {
			return mSharedPreferences.getString("uuid", null);
		}
		return null;
	}

	//用户accountId
	public void setAccountId(String accountId) {
		if (mSharedPreferences != null) {
			SharedPreferences.Editor editor = mSharedPreferences.edit();
			editor.putString("accountId", accountId);
			editor.commit();
		}
	}

	public String getAccountId() {
		if (mSharedPreferences != null) {
			return mSharedPreferences.getString("accountId", "");
		}
		return null;
	}
	//用户token
	public void setToken(String accountId) {
		if (mSharedPreferences != null) {
			SharedPreferences.Editor editor = mSharedPreferences.edit();
			editor.putString("token", accountId);
			editor.commit();
		}
	}
	public String getToken() {
		if (mSharedPreferences != null) {
			return mSharedPreferences.getString("token", "");
		}
		return null;
	}

	public Boolean getIsLog() {
		if (mSharedPreferences != null) {
			return mSharedPreferences.getBoolean("IsLog", false);
		}
		return null;
	}
	//用户t是否登录
	public void setIsLog(Boolean isLog) {
		if (mSharedPreferences != null) {
			SharedPreferences.Editor editor = mSharedPreferences.edit();
			editor.putBoolean("IsLog", isLog);
			editor.commit();
		}
	}


	//账号
	public void setAccount(String account) {
		if (mSharedPreferences != null) {
			SharedPreferences.Editor editor = mSharedPreferences.edit();
			editor.putString("account", account);
			editor.commit();
		}
	}

	public String getAccount() {
		if (mSharedPreferences != null) {
			return mSharedPreferences.getString("account", "");
		}
		return null;
	}
	//清除用户数据
	public void cleanData(){
		if (mSharedPreferences != null) {
			SharedPreferences.Editor editor = mSharedPreferences.edit();
			editor.putString("account", "");
			editor.putBoolean("IsLog",false);
			editor.putString("token", "");
			editor.putString("accountId", "");
			editor.commit();
		}
	}
}
